package com.zhisheng.demo03_Stream_Hello;

import java.util.OptionalDouble;
import java.util.stream.Stream;

/**
 * 创建者： 智晟全哥
 *
 * 练习Stream的终结方法
 *
 */
public class MyStream3 {
    public static void main(String[] args) {
        Stream<Integer> stream = Stream.of(2, 5, 8, 3, 6, 9, 1, 4, 7);
        // 统计个数
        //long count = stream.count();
        //System.out.println(count);
        //stream.forEach(s-> System.out.println(s));
//        Optional<Integer> max = stream.max((a, b) -> a - b);
//        Integer i = max.get();
//        System.out.println(i);
       // System.out.println(stream.min((a, b) -> a - b).get());
        OptionalDouble average = stream.mapToInt(s -> s).average();
        System.out.println(average.getAsDouble());

        Stream<String> stream2 = Stream.of("123","22","8","66");
        // 转int流
        int sum = stream2.mapToInt(s -> Integer.parseInt(s)).sum();
        System.out.println(sum);


    }
}
